package com.xinruke.hostels.reservation.controller.pms;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.EConditionOperator;
import com.xinruke.hostels.common.vo.query.QueryConditions;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.reservation.interfaces.dto.pms.*;
import com.xinruke.hostels.reservation.service.pms.BookingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassName RoomBookingController
 * @CreateDate 2019/7/3
 * @Author FengXinQiang
 * @Version V1.0.0.0
 * @Decription 房间预订Controller
 */
@RestController
@RequestMapping("/booking")
@Api(tags = "pms预订")
@Slf4j
public class BookingController extends BaseController {
    @Autowired
    BookingService bookingService;

    @PostMapping("/getBookingList")
    @ApiOperation("获取预订集合")
    public ResultVO<RowsDataVO<BookingQueryResultDTO>> getBookingList(@RequestBody @Valid BookingQueryDTO bookingQueryDTO) {
        ResultVO<RowsDataVO<BookingQueryResultDTO>> resultVO = ResultVO.fail();

        QueryConditions queryConditions = bookingQueryDTO.getQueryConditions();
        queryConditions.addCondition("zhuangtai", EConditionOperator.EQULS, bookingQueryDTO.getZhuangtai());
        queryConditions.addCondition("yudingleixing", EConditionOperator.EQULS, bookingQueryDTO.getYudingleixing());
        queryConditions.addCondition("yudingrenxingming", EConditionOperator.EQULS, bookingQueryDTO.getYudingrenxingming());
        queryConditions.addCondition("yudingrendianhua", EConditionOperator.EQULS, bookingQueryDTO.getYudingrendianhua());
        queryConditions.addCondition("zhengjianleixing", EConditionOperator.EQULS, bookingQueryDTO.getZhengjianleixing());
        queryConditions.addCondition("zhengjianhao", EConditionOperator.EQULS, bookingQueryDTO.getZhengjianhao());
        queryConditions.addCondition("ruzhushijian", EConditionOperator.GREATER, bookingQueryDTO.getRuzhushijianStart());
        queryConditions.addCondition("ruzhushijian", EConditionOperator.LESS, bookingQueryDTO.getRuzhushijianEnd());
        queryConditions.addCondition("likaishijian", EConditionOperator.GREATER, bookingQueryDTO.getLikaishijianStart());
        queryConditions.addCondition("likaishijian", EConditionOperator.LESS, bookingQueryDTO.getLikaishijianEnd());
        queryConditions.addCondition("chuangjianshijian", EConditionOperator.GREATER, bookingQueryDTO.getChuangjianshijianStart());
        queryConditions.addCondition("chuangjianshijian", EConditionOperator.LESS, bookingQueryDTO.getChuangjianshijianEnd());
        queryConditions.addCondition("dingdanhao", EConditionOperator.EQULS, bookingQueryDTO.getDingdanhao());
        queryConditions.addCondition("laiyuan", EConditionOperator.EQULS, bookingQueryDTO.getLaiyuan());

        RowsDataVO rowsDataVO = bookingService.getBookingList(bookingQueryDTO);

        resultVO = ResultVO.success();
        resultVO.setData(rowsDataVO);

        return resultVO;
    }

    @PostMapping("/getBookingDetail")
    @ApiOperation("获取预订详情")
    public ResultVO<BookingDetailQueryResultDTO> getBookingDetail(@RequestBody @Valid BookingDetailQueryDTO bookingDetailQueryDTO) {
        ResultVO<BookingDetailQueryResultDTO> resultVO = ResultVO.fail();

        BookingDetailQueryResultDTO bookingDetailQueryResultDTO = bookingService.getBookingDetail(bookingDetailQueryDTO);

        resultVO = ResultVO.success();
        resultVO.setData(bookingDetailQueryResultDTO);

        return resultVO;
    }

    @PostMapping("/cancelBooking")
    @ApiOperation("取消预订")
    public ResultVO<BookingCancelResultDTO> cancelBooking(@RequestBody @Valid BookingCancelDTO bookingCancelDTO) {
        ResultVO<BookingCancelResultDTO> resultVO = ResultVO.fail();

        resultVO = bookingService.cancelBooking(bookingCancelDTO);

        return resultVO;
    }
}
